package com.demo.rxjava

import io.reactivex.rxjava3.core.*
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
import java.util.concurrent.TimeUnit

class RxjavaDemoKotlin {
    val tag = "hehe"
}

fun main() {

    val mySingleObserver = object : SingleObserver<String> {
        override fun onSuccess(t: String?) {
            println("------$t")
        }

        override fun onSubscribe(d: Disposable?) {
            println("我被订阅了")
        }

        override fun onError(e: Throwable?) {
            e?.printStackTrace()
        }

    }
    Single.just(1)
            .map(object : io.reactivex.rxjava3.functions.Function<Int, String> {
                override fun apply(t: Int): String {
                    return "---$t"
                }

            })
            .subscribeOn(Schedulers.computation())
            .observeOn(Schedulers.io())
            .subscribe(mySingleObserver)


    Observable.interval(1, TimeUnit.SECONDS)
            .subscribe {
                println(it)
            }

}

